package com.attilax.shbye;

import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import com.attilax.img.imgx;
import com.attilax.lang.IniEx;
import com.attilax.secury.DESUtil;
import com.attilax.secury.yzmPropertyReader;

import compkg.CQZDMDLL.DM;

public class YejmX extends atiwrap {
	
	
	public static void main(String[] args) throws IOException, IniEx {
		String pathname = "c:\\0423_042128_451.jpg";
		BufferedImage img=ImageIO.read(new File(pathname));
		YejmX yx=new YejmX();
		yx.inix();
		System.out.println( yx.getResult(img));
		
	}

	public String mode;
	public ChkX chkx;
	public int prob;
	public Konfyoren kfyoren;

	public String getResult(BufferedImage img) {
		try {
//			if (chkx != null)
//				if (chkx.checkNotPass(imgUrl))
//					return this.NoCheckPassVal();
			if(img.getWidth()!=100 ||img.getHeight()!=40)
				throw new RuntimeException("not_img_suit_fmt");

			/*
			 * DLL 文件MD5值校验 用处：近期有不法份子采用替换 官方dll文件的方式，极大的破坏了开发者的利益
			 * 
			 * 所以建议所有开发者在软件里面增加校验官方MD5值的函数
			 * 
			 * checkAPiFile.java是已经写好的校验文件
			 */

			boolean apiCheckStatus = false;
			// apiCheckStatus=checkApiFile.check(DLLPATH+".dll", SOFTID,
			// SOFTKEY);
			apiCheckStatus = true;
			if (apiCheckStatus) { // 判断API文件是否被修改
				// inix();
				if (userID > 0) {
					// System.out.println("userID is:"+userID);
					// System.out.println("user score is:"+DM.INSTANCE.uu_getScoreA(USERNAME,
					// PASSWORD));

					if (filemode) {
//						File f = new File(img);
//						by = toByteArray(f);
					} else {
						by = imgx.toByteArray(img,"jpg");
					}

					if (test)
						return "testxx";
					byte[] resultBtye = new byte[30]; // 为识别结果申请内存空间
					int codeID = DM.INSTANCE.uu_recognizeByCodeTypeAndBytesA(
							by, by.length, 8001, resultBtye); // 调用识别函数,resultBtye为识别结果
					String resultResult = new String(resultBtye, "UTF-8");
					// String resultResult2 = new String(resultBtye,"gbk");
					resultResult = resultResult.trim();
					// System.out.println("this img codeID:"+codeID);

					result = resultResult;
					if (result.trim().startsWith("-")) {
						result = DESUtil.encryptByDes(resultResult);
						System.out.println(result);
						return result;
					}
					if(kfyoren!=null)
					result = kfyoren.exe(prob, result);
					System.out.println("rzt:" + result);
					return result;

				} else {
					System.out.println("er：ini"); // 错误代码请对应 各函数值查看
				}
			} else {
				// System.out.println("对不起，您替换了AP文件。 ");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		return null;
	}

	private String NoCheckPassVal() {
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "0000";
	}

}
